import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    song:{},
    playerState:undefined,
    currentTime:undefined,
    totalTime:undefined,
    index:undefined,
    songlist:undefined,
    albumPic:undefined
  },
  mutations: {
    changeSong(state,data){
      state.song = data;
    },
    // 更新状态
    changePlayerState(state,data){
      state.playerState = data;
    },
    // 更新时间
    timeupdate(state,data){
      state.totalTime = data.duration;
      state.currentTime = data.currentTime;
    },
    // 更新歌单
    getSonglist(state,data){
      state.songlist = data.songlist;
      state.index = data.index;
    },
    // 下一首
    nextSong(state){
      state.index++;
      if(state.index==state.songlist.length){
        state.index = 0;
      }
    },
    // 上一首
    prevSong(state){
      state.index--;
      if(state.index==-1){
        state.index = state.songlist.length -1;
      }
    },
    changeAlbum(state,data){
      state.albumPic = data;
    }
  },
  actions: {

  }
})
